// pages/tabBar/specialty/specialty.js
const http = require("../../../utils/httpUtils.js");
const app = getApp();
Page({
    data: {
        height: app.globalData.height,
        navHei: 0,
        showLoc: app.globalData.city,
        // hometown_memory_page: 2,
        // hometown_only_have_page: 2,
        // hometown_welfare_page: 2,
        headnav: [{
                "imgpath": 'historical_story.png',
                "text": '历史故事',
                "ac_mark": 'historical_story'
            },
            {
                "imgpath": 'tradition.png',
                "text": '风俗传统',
                "ac_mark": 'tradition'
            },
            {
                "imgpath": 'notability.png',
                "text": '著名人物',
                "ac_mark": 'notability'
            },
            {
                "imgpath": 'culture_art.png',
                "text": '文化艺术',
                "ac_mark": 'culture_art'
            },
        ],
        index: 0,
        cityArr: ['郑州市', '开封市', '洛阳市', '信阳市']
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.navWrapHeight() // 获取导航栏的高度
        this.index(this.data.showLoc)
    },
    index(cityName) {
        http._get('/api/index/index', { // 获取地市数据
            'city_name': cityName
        }, res => {
            if (res.data.code == 1) {
                let data = res.data.data;
                this.setData({
                    carousel: data.carousel, //轮播图
                    scenic: data.scenic_spot, // 风景点
                    scenic_spot_count: data.scenic_spot_count,
                    cate: data.cate, // 美食
                    cate_count: data.cate_count,
                    speciality: data.speciality, //特产
                    speciality_count: data.speciality_count

                })
                wx.stopPullDownRefresh()
            }
        })
    },
    // 选择地市
    bindPickerChange(e) {
        this.setData({
            index: e.detail.value
        })
        wx.setStorage({
            key: 'address',
            data: this.data.cityArr[e.detail.value]
        })
    },

    // 获取导航栏的高度
    navWrapHeight() {
        let query = wx.createSelectorQuery()
        query.select('.nav-wrap').boundingClientRect((res) => {
            this.data.navHei = res.height
        }).exec();
    },
    detail(e) { //进入详情
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: `/pages/public/article_detail/article_detail?id=${id}`,
        })
    },
    interHometownGroup() { // 进入话题聚合页
        wx.navigateTo({
            url: `/pages/group/hometowngroup/hometowngroup`,
        })
    },

    plantingDetail(e) { // 轮播图跳转文章详情
        let dataset = e.currentTarget.dataset;
        if (dataset.type == 1) {
            wx.navigateTo({
                url: `/pages/public/article_detail/article_detail?id=${dataset.id}`
            })
        } else if (dataset.type == 2) {
            wx.navigateTo({
                url: '/pages/activity/line001/index'
            })
        } else if (dataset.type == 3) {
            wx.navigateTo({
                url: `/pages/activity/line001/detail?id=${dataset.id}`
            })
        }
    },
    search() { // 搜索链接
        wx.navigateTo({
            url: `/pages/tabBar/index/search/se`,
        })
    },
    getList(e) { //获取分类列表
        let ac_mark = e.currentTarget.dataset.ac_mark;
        let data = {
            city_name: this.data.showLoc,
            ac_mark: ac_mark,
            page: 1
        }
        wx.navigateTo({
            url: `/pages/public/article_list/article_list?queryData=${JSON.stringify(data)}`,
        })

    },
    onPullDownRefresh() {
        this.index(this.data.showLoc);
    },
    onShareAppMessage() {
        return {
            title: `打造地方最具代表性、独特性的"家乡特色名片"`
        }
    }
})